using System;
using System.ComponentModel;
using System.Collections.Generic;

namespace shfa.snomtastic.data.business
{
	[DataObject(true)]
    public partial class PhoneController
    {
	
		public SqlDataProvider DataProvider { get; set; }

        public PhoneController()
        {
            DataProvider = new SqlDataProvider();
        }
	
		[DataObjectMethod(DataObjectMethodType.Insert, true)]
        public Guid InsertPhone(PhoneInfo oi)
		{
            return DataProvider.InsertPhone(oi.MacAddress, oi.UserId, oi.ConfigurationId, oi.IpAddress, oi.SubnetId, oi.SerialNumber, oi.UserAgent, oi.ModelId, oi.Model, oi.FirmwareId, oi.Firmware, oi.BootLoader, oi.Extension, oi.FirstFailedDate, oi.RegistrationFailed, oi.ReRegisterCount, oi.HttpClientPass, oi.CreatedDate, oi.UpdatedDate);
		}

		[DataObjectMethod(DataObjectMethodType.Update, true)]
        public int UpdatePhone(PhoneInfo oi) 
		{
			return DataProvider.UpdatePhone(oi.PhoneId, oi.MacAddress, oi.UserId, oi.ConfigurationId, oi.IpAddress, oi.SubnetId, oi.SerialNumber, oi.UserAgent, oi.ModelId, oi.Model, oi.FirmwareId, oi.Firmware, oi.BootLoader, oi.Extension, oi.FirstFailedDate, oi.RegistrationFailed, oi.ReRegisterCount, oi.HttpClientPass, oi.CreatedDate, oi.UpdatedDate);
		}
		
		[DataObjectMethod(DataObjectMethodType.Delete, true)]
        public int DeletePhone(Guid phoneId)
		{
			return DataProvider.DeletePhone(phoneId);
        }

		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public PhoneInfo SelectPhone(Guid phoneId)
        {    
			return ObjectFromDataRow(DataProvider.SelectPhone(phoneId));
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public List<PhoneInfo> SelectPhones()
		{
            return ListFromDataTable(DataProvider.SelectPhones());
        }
		
		[DataObjectMethod(DataObjectMethodType.Select, true)]
        public List<PhoneInfo> SelectPhones(string sortExpression)
        {
            List<PhoneInfo> retList = SelectPhones();
            if (sortExpression.Length > 0)
            {
                retList.Sort(new PhoneComparer(sortExpression));
            }
            return retList;
        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
		public List<PhoneInfo> SelectPhonesByConfiguration(Guid configurationId)
		{
			return ListFromDataTable(DataProvider.SelectPhonesByConfiguration(configurationId));
		}
		
        public List<PhoneInfo> SelectPhonesByConfiguration(Guid configurationId,string sortExpression)
		{
			List<PhoneInfo> retList = SelectPhonesByConfiguration(configurationId);
            if (sortExpression.Length > 0)
            {
                retList.Sort(new PhoneComparer(sortExpression));
            }
            return retList;
		}

        [DataObjectMethod(DataObjectMethodType.Select, true)]
		public List<PhoneInfo> SelectPhonesByFirmware(Guid firmwareId)
		{
			return ListFromDataTable(DataProvider.SelectPhonesByFirmware(firmwareId));
		}
		
        public List<PhoneInfo> SelectPhonesByFirmware(Guid firmwareId,string sortExpression)
		{
			List<PhoneInfo> retList = SelectPhonesByFirmware(firmwareId);
            if (sortExpression.Length > 0)
            {
                retList.Sort(new PhoneComparer(sortExpression));
            }
            return retList;
		}

        [DataObjectMethod(DataObjectMethodType.Select, true)]
		public List<PhoneInfo> SelectPhonesByModel(Guid modelId)
		{
			return ListFromDataTable(DataProvider.SelectPhonesByModel(modelId));
		}
		
        public List<PhoneInfo> SelectPhonesByModel(Guid modelId,string sortExpression)
		{
			List<PhoneInfo> retList = SelectPhonesByModel(modelId);
            if (sortExpression.Length > 0)
            {
                retList.Sort(new PhoneComparer(sortExpression));
            }
            return retList;
		}

        [DataObjectMethod(DataObjectMethodType.Select, true)]
		public List<PhoneInfo> SelectPhonesBySubnet(Guid subnetId)
		{
			return ListFromDataTable(DataProvider.SelectPhonesBySubnet(subnetId));
		}
		
        public List<PhoneInfo> SelectPhonesBySubnet(Guid subnetId,string sortExpression)
		{
			List<PhoneInfo> retList = SelectPhonesBySubnet(subnetId);
            if (sortExpression.Length > 0)
            {
                retList.Sort(new PhoneComparer(sortExpression));
            }
            return retList;
		}

        [DataObjectMethod(DataObjectMethodType.Select, true)]
		public List<PhoneInfo> SelectPhonesByUser(Guid userId)
		{
			return ListFromDataTable(DataProvider.SelectPhonesByUser(userId));
		}
		
        public List<PhoneInfo> SelectPhonesByUser(Guid userId,string sortExpression)
		{
			List<PhoneInfo> retList = SelectPhonesByUser(userId);
            if (sortExpression.Length > 0)
            {
                retList.Sort(new PhoneComparer(sortExpression));
            }
            return retList;
		}

	}

}
		